package com.guoqi.wolf2w.redis.impl;

import com.alibaba.fastjson.JSON;
import com.guoqi.wolf2w.domain.UserInfo;
import com.guoqi.wolf2w.redis.IUserInfoRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class UserInfoRedisService implements IUserInfoRedisService {


    @Autowired
    private StringRedisTemplate template;

    @Override
    public String setToken(String token, UserInfo userInfo) {
        String uid = UUID.randomUUID().toString().replaceAll("-","");
        template.opsForValue().set(userInfo.getNickname()+":"+token, JSON.toJSONString(userInfo),300, TimeUnit.SECONDS);
        return userInfo.getNickname()+":"+token;
    }
}
